package gozerocommon

import (
	"fmt"

	"github.com/speps/go-hashids/v2"
)

type HashId struct {
	hd *hashids.HashIDData
}

func (hi *HashId) New(salt string, minLength int) *HashId {
	var hd = hashids.NewData()
	hd.Salt = salt
	hd.MinLength = minLength
	return &HashId{hd: hd}
}

func (hi *HashId) IdToString(id int64) string {
	h, _ := hashids.NewWithData(hi.hd)
	e, _ := h.EncodeInt64([]int64{id})
	return e
}

func (hi *HashId) StringToid(id string) int64 {
	h, _ := hashids.NewWithData(hi.hd)
	d, _ := h.DecodeInt64WithError(id)
	fmt.Println(d[0])
	return d[0]
}
